package com.wondersgroup.fjzlpt.tbxt.dao.impl.jc;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.repository.sql.bean.SQLBean;
import com.quick.framework.boot.repository.sql.bean.table.TableBean;
import com.quick.framework.boot.repository.sql.jdbcTemplate.impl.BaseJTDAOImpl;
import com.wondersgroup.fjzlpt.tbxt.dao.inter.jc.JcJbDao;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 基层季报
 */
@Repository
public class JcJbDaoImpl extends BaseJTDAOImpl implements JcJbDao{

	@Override
	@Autowired
	@Qualifier("TB_TBXT_JC_JCXX_JB")
	public void setTb(TableBean tb) {
		super.setTb(tb);
	}

	@Override
	public JSONObject queryId(Map<String, String> map) {
		StringBuffer sqlBuf = new StringBuffer("select ID from ").append(this.tb.getTableName());
		sqlBuf.append(" where JD = ? and NF = ? and YLJGID = ? ");
		SQLBean bean = new SQLBean(sqlBuf.toString(), map.get("JD"), map.get("NF"), map.get("YLJGID"));
		return super.queryOne(bean);
	}


	@Override
	public JSONObject queryOne(Map<String, String> map) {
		StringBuffer sqlBuf = new StringBuffer("select * from ").append(this.tb.getTableName()).append(" where 1=1 ");
		List sqlParams = new ArrayList();
		String value = map.get("ID");
		if(!StringUtils.isEmpty(value)){
			sqlBuf.append("and ID = ? ");
			sqlParams.add(value);
		}else{
			sqlBuf.append("and JD = ? and NF = ? and YLJGID = ? ");
			sqlParams.add(map.get("JD"));
			sqlParams.add(map.get("NF"));
			sqlParams.add(map.get("YLJGID"));
		}
		SQLBean bean = new SQLBean(sqlBuf.toString(), sqlParams.toArray());
		return super.queryOne(bean);
	}

}
